package org.liubility.server.robot.controller;

import com.jdragon.common.json.JsonUtils;
import com.jdragon.common.response.normal.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.liubility.pojo.dto.RobotMsgResult;
import org.liubility.pojo.entity.RobotPostOrder;
import org.liubility.pojo.exception.LBException;
import org.liubility.server.robot.service.RobotPostOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: Jdragon
 * @email: 1061917196@qq.com
 * @Date: 2020.09.03 22:57
 * @Description:
 */

@RestController
@RequestMapping("/robot")
@Api(tags = "机器人接口")
public class RobotController {

    @Autowired
    private RobotPostOrderService robotPostOrderService;

    @GetMapping("/getPostOrder")
    @ApiOperation("获取注册指令列表")
    public Result<List<RobotPostOrder>> getPostOrder() {
        return Result.success(robotPostOrderService.getPostOrder());
    }

    @PostMapping("/addPostOrder")
    @ApiOperation("添加指令映射")
    public Result<RobotPostOrder> addPostOrder(@RequestBody RobotPostOrder robotPostOrder) throws LBException {
        return Result.success(robotPostOrderService.addPostOrder(robotPostOrder));
    }

    @GetMapping("/test")
    @ApiOperation("test")
    public Result<RobotMsgResult> getTest(RobotMsgResult robotMsgResult) {
        String param = robotMsgResult.getParam();
        Map<String, Object> stringObjectMap = JsonUtils.str2Map(param);
        System.out.println(stringObjectMap);
        robotMsgResult.setMessage(robotMsgResult.getParam());
        return Result.success(robotMsgResult);
    }

    @PostMapping("/test")
    @ApiOperation("test")
    public Result<RobotMsgResult> postTest(@RequestBody RobotMsgResult robotMsgResult) {
        robotMsgResult.setMessage(robotMsgResult.getParam());
        return Result.success(robotMsgResult);
    }
}
